import { APP_BASE_SOCKET_URL } from '@/config'
import { useWebSocket, type UseWebSocketOptions } from '@vueuse/core'
import { computed,  type ComputedRef } from 'vue'

const hostsocket = 'wss://' + location.host
export function useSocket(options: UseWebSocketOptions, socketId: ComputedRef<string>) {
  const socketURL = computed(() => {
    return `${
      process.env.NODE_ENV === 'development' ? APP_BASE_SOCKET_URL : hostsocket
    }/ws/chat/frontend/ws/${socketId.value}`
  })
  const socket = useWebSocket(socketURL.value, options)
  return socket
}
